/*
*
==============================================================================
*  Name        : 
*  Part of     : Omen Game Engine - DirectX 10 Plugin
*  Description : 
*  Version     : 1.0
*
*  Copyright (c) 2013 Lauri Kortevaara.
* 
==============================================================================
*/

#ifndef _DirectX_10__DRIVER_H_
#define _DirectX_10__DRIVER_H_

///////////////////////////////////////////////////////////////////////////////
// Omen Game Engine class                                               //
//                                                                           //
//                                                                           //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
#define DIRECTX_10_PLUGIN_SOURCE 1

#include <OmenEngine>

#include "DirectX_10_Renderer.h"

/////////////
// LINKING //
/////////////
#pragma comment(lib, "d3d10.lib")
#pragma comment(lib, "d3dx10.lib")
#pragma comment(lib, "dxgi.lib")

//////////////
// INCLUDES //
//////////////
#include <d3d10.h>
#include <d3dx10.h>

namespace Omen {

    typedef std::vector< IDXGIOutput* > AdapterOutputs;
    typedef DXGI_RATIONAL               DXGI_ScreenRefreshRate;

    /// DirectX_10_ graphics drver
    class DirectX_10_GraphicsDriver : public Omen::IGraphicsDriver
    {

    public: 
        DIRECTX_10_PLUGIN_API DirectX_10_GraphicsDriver(); /// <summary>Creates an DirectX_10_ graphics driver</summary>
        DIRECTX_10_PLUGIN_API virtual ~DirectX_10_GraphicsDriver(); /// <summary>Destroys an DirectX_10_ graphics driver</summary>

        /// <summary>Gets the name of the graphics driver</summary>
        virtual const std::wstring &getName() const;

        void operator()() const; // Slot

        void setActive( const bool &bActive ) { m_bIsActive = bActive; }

        /// <summary>Creates a renderer</summary>
        virtual Omen::IRenderer* createRenderer();

    protected:
        bool initialize();

        bool create_DXGI_Factory(); // Creates the DXGI Factory
        bool enumerate_DXGI_Adapters(); // Enumerates the Graphics Adapters existing in the system
        bool enumerate_DXGI_AdapterOutputs( IDXGIAdapter* pAdapter = NULL );

        bool getCurrentAdapterInfo();
        bool findDisplayMode( IDXGIOutput* pOutput = NULL );
        bool create_SwapChain();

    private:
        bool                                m_bIsActive;
        DirectX_10_Renderer*                m_renderer;

        bool m_vsync_enabled;
        int m_videoCardMemory;
        char m_videoCardDescription[128];
        
        

        // DXGI (DirectX Graphics Infrastrcture) related things
        IDXGIFactory*                   m_pDXGIFactory; // The interface factory
        std::vector< IDXGIAdapter* >    m_vDXGIAdapters; // DXGI Adapter interfaces

        std::map< IDXGIAdapter*, AdapterOutputs > m_mapDXGIOutputs; // 

        IDXGIAdapter*                   m_pCurrentAdapter;
        IDXGIOutput*                    m_pCurrentOutput;

        int                             m_screenWidth;
        int                             m_screenHeight;

        DXGI_ScreenRefreshRate          m_screenRefreshRate;
    };
} // namespace Omen

#endif